var gulp = require('gulp');
var fs = require('fs');
var contentIncluder = require('./');
var rename = require('gulp-rename');
var data=JSON.parse(fs.readFileSync("2.json"));

var tel;
var header='<!--include "./header.html"-->';
var footer='<!--include "./footer.html"-->';
for(var i=0;i<data.length;i++){
                
    var href=data[i].href;
    var title=data[i].title;
    var img=data[i].img;
    var content=data[i].content;
                    var numL=href.split("=");
                    pa=numL[0];
                    pb=numL[1].split("&");
                    pc=numL[2];
    var nhref="\"href\":"+"\""+pa+"="+i+"&"+pb[1]+"="+pc+"\"";
    var ntitle=",\"title\":"+"\""+title+"\"";
    var nimg=",\"img\":"+"\""+img+"\"";
    var ncontent=",\"title\":"+"\""+content+"\"";
    
                    tel=header+"{"+nhref+ntitle+nimg+ncontent+"},"+footer;
                    fs.writeFile(i+".html",tel);
                }

gulp.task('default',function() {
    gulp.src("./*.html")
        .pipe(contentIncluder({
            includerReg:/<!\-\-include\s+"([^"]+)"\-\->/g,
            deepConcat: true,
            baseSrc: './'
        }))
        .pipe(gulp.dest('./c/'));
});
